package tuillayer;
import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * Textbased UI which allows the user to input information about persons.
 * @author (Søren Kaae)
 */
public class MainMenuUI
{
    
    /** The DVD UI. */
    private DVDUI dvdUI;
    
    /** The Person UI. */
    private PersonUI pUI;

    /** The Loan UI. */
    private LoanUI lUI;

    /**
     * The main method.
     *
     * @param args the arguments
     */
    public static void main(String[] args)
    {
        MainMenuUI mainMenuUI;
        mainMenuUI = new MainMenuUI();
        mainMenuUI.mainMenu();
    }

    /**
     * Instantiates a new main menu ui.
     */
    public MainMenuUI()
    {
    	pUI = PersonUI.getInstance();
        dvdUI = DVDUI.getInstance();
        lUI = LoanUI.getInstance();
  
    }

    /**
     * Main menu.
     */
    public void mainMenu()
    {
        boolean exit = false;
        try {
        while(!exit)//that is: while exit is false
        {
            int choice = writeMainMenu(); 
            if(choice == 1)
            {   //Create dvd
                pUI.personMenu();
            }
            else if(choice == 2)
            { //find dvd			    
                dvdUI.dvdMenu();
            } 
            else if(choice == 3)
            {
                // Loan menu
            	lUI.loanMenu();
            }		
            else
            {
                exit = true;
            }//end else

        }//end while
        }//end try
        catch (InputMismatchException e)
        {
            //Prints appropriate error message
            System.out.println("Du skal indtaste et tal!");
            mainMenu();
        }
    }

    /**
     * Write main menu.
     *
     * @return the int
     */
    public int writeMainMenu()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("*** Main Menu ***");
        System.out.println(" (1) Friends");
        System.out.println(" (2) DVDs");
        System.out.println(" (3) Loan");
        System.out.println(" (4) Exit");
        System.out.print("\n Choose: ");
        int choice = keyboard.nextInt();
        return choice;
    }

    
}
